package com.bdqn.qnnews.wemedia.controller.v1;

import com.bdqn.qnnews.common.base.PageResult;
import com.bdqn.qnnews.common.base.R;
import com.bdqn.qnnews.wemedia.entity.WmMaterial;
import com.bdqn.qnnews.wemedia.service.WmMaterialService;
import com.bdqn.qnnews.wemedia.vo.MaterialVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author xlz
 * @since 2023-12-26
 * @description 自媒体图文素材信息表
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v1")
@Tag(name = "自媒体图文素材信息表控制器类",
        description = "WmMaterialController 自媒体图文素材信息表 后端数据接口")
public class WmMaterialController {

    private final WmMaterialService wmMaterialService;

    /**
     * 上传图片素材
     * @param multipartFile 上传素材的key名称
     * @return Result
     */
    @Operation(summary = "上传图片素材", description = "上传图片素材")
    @PostMapping("/material/upload_picture")
    public R<WmMaterial> uploadMaterial(MultipartFile multipartFile) {
        final WmMaterial wmMaterial = wmMaterialService.uploadPicture(multipartFile);
        return R.ok(wmMaterial);
    }

    /**
     * 查询素材列表
     * @param materialVo 条件参数
     * @return Result
     */
    @Operation(summary = "上传图片素材", description = "上传图片素材")
    @PostMapping("/material/list")
    public PageResult<List<WmMaterial>> uploadMaterial(@RequestBody MaterialVo materialVo) {
        return wmMaterialService.findList(materialVo);
    }


    /**
     * 删除素材
     * @param mId 素材id
     * @return Result
     */
    @Operation(summary = "删除素材", description = "删除素材")
    @GetMapping("/material/del_picture/{mId}")
    public R<String> deleteMaterial(@PathVariable("mId") Long mId) {
        boolean res = wmMaterialService.removeMaterial(mId);
        return R.ok("删除成功");
    }


}
